package com.eduhzy.ttw.teacher.mvp.ui.adapter;

import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.eduhzy.ttw.commonsdk.core.Constants;
import com.eduhzy.ttw.commonsdk.entity.HomeListData;
import com.eduhzy.ttw.commonsdk.entity.HomeSection;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.eduhzy.ttw.teacher.R;

import java.util.List;

import static com.eduhzy.ttw.commonsdk.core.Constants.HOME_ITEM_TYPE.ITEM_HEAD;
import static com.eduhzy.ttw.commonsdk.core.Constants.HOME_ITEM_TYPE.ITEM_HOME;

/**
 * @author xubo
 * @date 2018/7/20 13:52
 */
public class HomeMultiAdapter extends BaseMultiItemQuickAdapter<HomeSection<HomeListData>, AutoBaseViewHolder> {
    private boolean showMore;

    public boolean isShowMore() {
        return showMore;
    }

    public void setShowMore(boolean showMore,int position) {
        this.showMore = showMore;
        if (onShowMoreChangeListener != null) {
            onShowMoreChangeListener.onShowMoreChange(showMore,position);
        }
    }

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public HomeMultiAdapter(List<HomeSection<HomeListData>> data) {
        super(data);
        this.addItemType(ITEM_HEAD, R.layout.rv_item_home_header);
        this.addItemType(Constants.HOME_ITEM_TYPE.ITEM_HOME, R.layout.rv_item_home);
    }

    @Override
    protected void convert(AutoBaseViewHolder helper, HomeSection<HomeListData> item) {
        switch (helper.getItemViewType()) {
            case ITEM_HEAD:
                helper.setImageResource(R.id.iv_avatar, item.getImg());
                helper.setText(R.id.tv_name, item.getName());
                break;
            case ITEM_HOME:
                helper.setText(R.id.tv_title, item.getT().getTitle());
                String desc = item.getT().getDesc();
                helper.setText(R.id.tv_desc, desc);
                helper.setText(R.id.tv_time, item.getT().getDate());
                helper.setText(R.id.btn_count, item.getT().getCount() + "");
                helper.setGone(R.id.btn_count, item.getT().getCount() > 0);
                Glide.with(mContext)
                        .load(item.getT().getResId())
                        .into((ImageView) helper.getView(R.id.iv_avatar));
                break;
            default:
                break;
        }
    }
    private OnShowMoreChangeListener onShowMoreChangeListener;

    public OnShowMoreChangeListener getOnShowMoreChangeListener() {
        return onShowMoreChangeListener;
    }

    public void setOnShowMoreChangeListener(OnShowMoreChangeListener onShowMoreChangeListener) {
        this.onShowMoreChangeListener = onShowMoreChangeListener;
    }

    public interface OnShowMoreChangeListener {
        void onShowMoreChange(boolean isShowMore, int position);
    }

}
